package com.king.login.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.king.login.dao.MemberMenuMapper;
import com.king.login.entity.MemberMenu;
import com.king.login.param.MemberMenuParam;
import com.king.login.service.MemberMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * <p>todo MemberMenu 服务接口实现</p>
 * @author: cuizx
 * @created: 2024-03-29 20:55:09
 * @version v1.0.1
 * @copyright: Copyright (c)  cuizx
 */
@Service("memberMenuService")
public class MemberMenuServiceImpl extends ServiceImpl<MemberMenuMapper, MemberMenu> implements MemberMenuService
{


  @Resource
  private MemberMenuMapper memberMenuMapper;

  /**
   * <p>todo 批量删除</p>
   * @param: ids
   * @return: MemberMenu
   * @author: cuizx
   * @date: 2024-03-29 20:55:09
   * @version: 1.0.1
   * Modification History:
   * Date         Author          Version            Description
   * -----------------------------------------------------------
   * 2024-03-29 20:55:09    cuizx        v1.0.1             init
   */

  @Override
  public void deleteByIds(String ids)
  {
    String[] idsArr = ids.split(",");
    if (idsArr.length > 0)
    {
      List<Long> idList = Stream.of(idsArr).map(Long::valueOf).collect(Collectors.toList());
      memberMenuMapper.deleteBatchIds(idList);
    }
  }


  /**
   * <p>todo 查询所有</p>
   * @param: model
   * @return: MemberMenu
   * @author: cuizx
   * @date: 2024-03-29 20:55:09
   * @version: 1.0.1
   * Modification History:
   * Date         Author          Version            Description
   * -----------------------------------------------------------
   * 2024-03-29 20:55:09    cuizx        v1.0.1             init
   */

  @Override
  public List<MemberMenu> list(MemberMenuParam model)
  {

    //条件查询
    QueryWrapper<MemberMenu> queryWrapper = new QueryWrapper();

    //动态sql
    //if(StringUtils.isNotBlank(model.getAuthor())){
    // queryWrapper.lambda().eq(MemberMenu::getAuthor,model.getAuthor());
    // }

    //排序
    queryWrapper.lambda().orderByDesc(MemberMenu::getId);

    //执行查询
    List<MemberMenu> tempList = memberMenuMapper.selectList(queryWrapper);

    //封装查询结果
    return tempList;
  }

  /**
   * <p>todo 分页查询</p>
   * @param: model
   * @return: MemberMenu
   * @author: cuizx
   * @date: 2024-03-29 20:55:09
   * @version: 1.0.1
   * Modification History:
   * Date         Author          Version            Description
   * -----------------------------------------------------------
   * 2024-03-29 20:55:09    cuizx        v1.0.1             init
   */

  @Override
  public PageInfo<MemberMenu> listPage(MemberMenuParam model)
  {

//没有传分页参数时，默认设置查询前10条数据
    if (null == model.getPageSize())
    {
      PageHelper.startPage(model.DEFAULT_PAGE, model.DEFAULT_SIZE);
    } else
    {
      PageHelper.startPage(model.getCurrentPage(), model.getPageSize());
    }

    //条件查询
    QueryWrapper<MemberMenu> queryWrapper = new QueryWrapper();

    //动态sql
    //if (StringUtils.isNotBlank(model.getAuthor())) {
    //    queryWrapper.lambda().eq(Member::getAuthor, model.getAuthor());
    // }
    //排序
    queryWrapper.lambda().orderByDesc(MemberMenu::getId);

    //执行查询
    List<MemberMenu> list = memberMenuMapper.selectList(queryWrapper);
    PageInfo<MemberMenu> pageInfo = new PageInfo<>(list);

    //封装查询结果
    return pageInfo;
  }


}


